package pack3;

import java.util.Arrays;

public class ShellSort {
    public static void main(String[] args) {
        int []arr=new int[]{7,5,6,9,10,1,3,7,4,3,2,1,4,2};
        shellSort(arr);
        System.out.println(Arrays.toString(arr));

    }


    public static void shellSort(int[]arr){
        int gap=5;
        while(gap>1){
            shell(arr,gap);
            gap/=2;
        }
        shell(arr,1);
    }

    public static void shell(int[]arr,int gap){
        for (int i = gap; i <arr.length ; i++) {
            int temp = arr[i];
            int j;
            for (j = i-gap; j >=0; j -= gap) {
                if (arr[j] > temp) {
                    arr[j + gap] = arr[j];
                } else {
                    break;
                }
            }
            arr[j + gap]=temp;
        }

    }


}
